home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 31
/
Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso
/
Aminet
/
dev
/
c
/
GAPLib.lha
/
GAPLib_Beta
/
diagnostic
/
GaussRandTest.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-04-22
|
902b
|
61 lines
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <GAP.h>
int main(void)
{
int ret=0;
int i,n;
int *sumar;
double d,q,err;
InitRand(time(0));
sumar = malloc(sizeof(double)*129);
if(sumar!=0) {
for(i=0;i!=129;i++) {
sumar[i] = 0.0;
}
for(i=0;i!=1048076;i++) {
d = GaussRand(0.0,0.8);
n = (int)(32.0*d)+64;
if(n>=0 && n<128) {
sumar[n] = sumar[n] + 1.0;
}
if((i&32767)==32767) {
fputc('.',stdout);
fflush(stdout);
}
}
sumar[64] = sumar[64]/2.0; /* This feels like a bug. */
q=1.0/(sumar[64]);
err = 0.0;
for(i=0;i!=129;i++) {
d = exp(-pow(i/32.0-2,2.0));
err = err + pow((d-sumar[i]*q),2.0);
}
printf("(%lf)\n",err);
if(err<1.41421356) {
printf("No worse than usual.\n");
} else {
printf("This sucks.\n");
ret = 5;
}
free(sumar);
} else {
fprintf(stderr,"No free store. (malloc() failed)\n");
}
return(ret);
}